﻿<%@ Page Language="C#" validateRequest='false' AutoEventWireup="true" CodeFile="LogInfo.aspx.cs" Inherits="log_LogInfo" %>

<%@ Register Assembly="FreeTextBox" Namespace="FreeTextBoxControls" TagPrefix="FTB" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
       <title>写日志</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="../css/ss01.css" />
	<link rel="stylesheet" type="text/css" href="../css/stylesheet.css"/>
    <script language="JScript" src="../js/Function.js"></script>
    <script language="JScript" src="../js/myCheck.js"></script>
    <script language="JScript" src="../jquery/126/jquery-1.2.6.js"></script>

    <script type="text/javascript" language="javascript">
        var checkgoto=true;
        setInterval("findFinC()",8000);
        function GoToUrl( )
        {
        
            if($('#hfid').val()=="")
            {
                if($('#txttitle').val() !="" || document.getElementById('FreeTextBox1').value != "" )
                {
                    
                    window.event.returnValue = '日记已改变，尚未保存，是否离开？';
                }
                else
                {
                   
                }
            }
            else
            {
                var urlstring="LogInfo.aspx";
                $.ajax({
	            url:urlstring,
	            type:'post',
	            dataType:'html',
	            data:'operation=checkchange'+"&id=" + $("#hfid").val() + '&title='+ $("#txttitle").val() + '&content='+document.getElementById('FreeTextBox1').value ,
	            beforeSend:function()
	            {
	                $("#divmsg").empty().append("<img id='loading' src='../images/spinner.gif' />正在加载,请稍等......");
	            },
	            error:function()
	            {
	                $("#divmsg").empty().append("read error!");
	            },
	            success: function(msg)
	            {
	                $("#divmsg").empty();
	               
	                if(msg=='ischanged' && checkgoto)
	                {
                        if(confirm( '日记已改变，尚未保存，是否保存？'))
                        {
                            save(0);
                        }
	                }
	                checkgoto=true;
	            }
	            });
            }
            
           
//            if($('#hfid').val()=="")
//            {
//                if($('#txttitle').val() !="" || document.getElementById('FreeTextBox1').value != "" )
//                {
//                    if( confirm('日记已改变，尚未保存，是否离开？') ){if( url == 'back' ){ window.history.back(); } else { location.href=url; }}
//                }
//                else
//                {
//                    if( url == 'back' ){ window.history.back(); } else { location.href=url; }
//                }
//            }
//            else
//            {
//                var urlstring="LogInfo.aspx";
//                $.ajax({
//	            url:urlstring,
//	            type:'post',
//	            dataType:'html',
//	            data:'operation=checkchange'+"&id=" + $("#hfid").val() + '&title='+ $("#txttitle").val() + '&content='+document.getElementById('FreeTextBox1').value ,
//	            beforeSend:function()
//	            {
//	                $("#divmsg").empty().append("<img id='loading' src='../images/spinner.gif' />正在加载,请稍等......");
//	            },
//	            error:function()
//	            {
//	                $("#divmsg").empty().append("read error!");
//	            },
//	            success: function(msg)
//	            {
//	                $("#divmsg").empty();
//	                if(msg=='ischanged'){if(confirm('日记已改变，尚未保存，是否离开？')){if( url == 'back' ){ window.history.back(); } else { location.href=url; }}}
//	                else{if( url == 'back' ){ window.history.back(); } else { location.href=url; }}
//	                
//	            }
//	            });
//             }
        }
        
		function chk() 
		{
			if($('#txttitle').val()==""){ alert('你还没有写日记标题呢！'); return false;}
			if(document.getElementById('FreeTextBox1').value == ""){alert('日记里一点内容都还没写，这样不好吧？'); return false;}
			return true;
		}
		function msg()
		{
		    //FTB_CopyHtmlToHidden(FreeTextBox1_editor,document.getElementById('FreeTextBox1'),FreeTextBox1_HtmlMode);
		    //document.getElementById('FreeTextBox1').focus();
		    
		    alert(document.getElementById('FreeTextBox1').value);
		    
		}
		setInterval("save('0');",180000);
		
		function save(savetype){
		//this.focus();
        if($('#txttitle').val() =="" && document.getElementById('FreeTextBox1').value == "" )
        {
            return;
        }
		else
		{
		    if(savetype=='1' && !chk())
		        return;
		}
	    var urlstring="LogInfo.aspx";
	    var auth=$('input[@name=rblauthority][@checked]').val()==null? 0 :$('input[@name=rblauthority][@checked]').val(); 
		$.ajax({
	            url:urlstring,
	            type:'post',
	            dataType:'html',
	            data:'operation=save'+"&id=" + $("#hfid").val() + '&savetype='+ savetype + '&title='+ escape($("#txttitle").val()) + '&authority=' + auth + '&type=' +$("#ddltype").val()+'&content='+escape(document.getElementById('FreeTextBox1').value) + '&hffriend=' + $('#hffriend').val(),
	            beforeSend:function()
	            {
	                $("#divmsg").empty().append("<img id='loading' src='../images/spinner.gif' />正在加载,请稍等......");
	            },
	            error:function()
	            {
	                $("#divmsg").empty().append("read error!");
	            },
	            success: function(msg)
	            {
	                $('#hfid').val(msg);
	                $("#divmsg").empty();
	                if(savetype=='1')
	                    location.href="log.aspx";
	            }
	        });
	    }
	    
	    function SchFiend()
	    {
	        var schstr=$.trim($("#txtsch").val().substr($("#txtsch").val().lastIndexOf(',')+1));
	        
	        $("#selectdiv").show()
	        var urlstring="FriendList.aspx";
            $.ajax({
            url:urlstring,
            type:'post',
            dataType:'html',
            data:'searchstr='+schstr +'&exstr='+$("#hffriend").val(),
            beforeSend:function()
            {
                $("#selectdiv").empty().append("<img id='loading' src='../images/spinner.gif' />正在加载,请稍等......");
            },
            error:function()
            {
                $("#selectdiv").empty().append("read error!");
            },
            success: function(msg)
            {
                $("#selectdiv").empty().append(msg);
            }
            });
	    }
	    function addfriend()
        {
            $.each($("input:checked"),function(i,n){$("#txtlf").prepend("<span id='"+ n.name + "' style='border-style:solid; border-color:red; border-width:1px;'>&nbsp;"+n.value+"<a href='#' style='color:Red' onclick='javascript:delfriend($(this),"+ n.name +")'><strong >×</strong></a>&nbsp;</span>");$("#hffriend").val($("#hffriend").val()+","+n.name);});
            $("#selectdiv").hide();
            $("#txtsch").val("");
            
        }
        function delfriend(obj,id)
        {
            obj.parent().remove();
            $("#hffriend").val($("#hffriend").val().replace(","+id,""));
            $("#hfdelids").val($("#hfdelids").val() + "," + id);
            
        }
        
        function findFinC()
        {
            var urlstring="LogInfo.aspx";
            FTB_CopyHtmlToHidden(FreeTextBox1_editor,document.getElementById('FreeTextBox1'),FreeTextBox1_HtmlMode);
		    $.ajax({
	                url:urlstring,
	                type:'post',
	                dataType:'html',
	                data:'operation=findF'+'&content='+escape(document.getElementById('FreeTextBox1').value) + '&ids='+ $("#hfdelids").val(),
	                beforeSend:function()
	                {
	                },
	                error:function()
	                {
	                    $("#divmsg").empty().append("read error!");
	                },
	                success: function(msg)
	                {
	                    
	                    var id;
	                    var name;
	                    var strs;
	                    strs=msg.split(';');
	                    $("#txtlf > span").remove();
	                    $("#hffriend").val("");
	                    for(i=0;i<strs.length;i++)
	                    {
	                        if(strs[i].indexOf(',')!=-1)
                            {
                                id=strs[i].substr(0,strs[i].indexOf(','));
                                name=strs[i].substr(strs[i].indexOf(',')+1);
                                $("#txtlf").prepend("<span id='"+ id + "' style='border-style:solid; border-color:red; border-width:1px;'>&nbsp;"+ name +"<a href='#' style='color:Red' onclick='javascript:delfriend($(this),"+ id +")'><strong >×</strong></a>&nbsp;</span>");$("#hffriend").val($("#hffriend").val()+","+ id);
                            }
	                    }
	                }
	            });
        }
        
        function test()
	    {
	        var a=form1.txtsch.value.substr(form1.txtsch.value.lastIndexOf(',')+1);
	        if($.trim(a)!="")
	        {
	            alert(a);
	        }
	    }
    </script>
</head>
<body onbeforeunload='GoToUrl()' >
    <form id="form1" runat="server">
    <div>
		<table cellSpacing="0" cellPadding="0" border="0" align="center">
		    <tr>
		        <td style="background-color:White;padding-right: 10px; padding-left: 10px; padding-bottom: 10px; padding-top: 10px;">
		            <table cellSpacing="0" cellPadding="0" width="500" align="center" border="0" style="background-color:White;">
		                <tr>
		                    <td style="BORDER-RIGHT: #90b0de 1px solid; BORDER-TOP: #90b0de 1px solid; BORDER-LEFT: #90b0de 1px solid; BORDER-BOTTOM: #90b0de 1px solid">
		                        <table width="100%" cellSpacing="0" cellPadding="0" align="center" border="0">
		                            <tr height="30">
		                                <td style="border-bottom: #90b0de 1px solid;font-weight: bold; color: #004499;border-bottom:1px solid silver;">&nbsp;&nbsp;&nbsp;<img src="../images/ico_rj.gif" />写日志</td><td style="border-bottom: #90b0de 1px solid;font-weight: bold; color: #004499;border-bottom:1px solid silver;text-align:right;" ></td>
		                            </tr>
		                        </table>
                                <div id="mnginput" style="margin-top:10px;margin-bottom:10px;margin-left:10px;">
                                <div id='divmsg'></div>
                                    <table width="100%" border='0'>
                                        <tr>
                                            <td align="right"  style=" width:50px;word-break: keep-all;">标题：</td>
                                            <td >
                                                <asp:TextBox ID="txttitle" runat="server"></asp:TextBox></td>
                                        </tr>
                                        <tr>
                                            <td align="right"></td>
                                            <td><asp:RadioButtonList ID="rblauthority" runat="server" RepeatDirection="Horizontal">
                                                    <asp:ListItem Value="1">公开</asp:ListItem>
                                                    <asp:ListItem Value="2">不公开</asp:ListItem>
                                                    <%--<asp:ListItem Value="3">凭密码</asp:ListItem>--%>
                                                </asp:RadioButtonList></td>
                                        </tr>
                                        <tr>
                                            <td align="right">分类：</td>
                                            <td>
                                                <asp:DropDownList ID="ddltype" runat="server">
                                                </asp:DropDownList>
                                                [<a href='logtype.aspx'>管理分类</a>]
                                                </td>
                                        </tr>
                                        <tr>
                                            <td align="right" valign="top">内容：</td>
                                            <td>
                                                <FTB:FreeTextBox ID="FreeTextBox1" runat="server" ButtonPath="../images/ftb/office2003/" AutoConfigure="Default" HelperFilesPath="" ToolbarType="Office2003" DownlevelMode="BasicEditor">
                                                </FTB:FreeTextBox>
                                            
                                            </td>
                                        </tr>
                                        <tr id="trtempsave" runat="server" >
                                            <td></td>
                                            <td ><font color="green" >每隔3分钟，系统自动将已写文字存为草稿，保存在暂存草稿夹中。</font> &nbsp;&nbsp;<input type="button" id='btsave' value='暂存草稿' onclick='save("0");' /></td>
                                        </tr>
                                        <tr>
                                            <td></td>
                                            <td>在这篇日记中提到的好友：</td>
                                        </tr>
                                        <tr>
                                            <td><asp:HiddenField ID ="hffriend" runat="server"/><asp:HiddenField ID='hfdelids' runat="server" /></td>
                                            <td><table border='0'><tr><td><div class='InputDiv' id='txtlf' runat="server"><input class='nonInput' id='txtsch' onkeyup='SchFiend()' type="text" /><img src="../images/xx_xx2.gif" onclick ='SchFiend()' /></div></td></tr></table><br /><div style="position:absolute; background-color:White;border:1px ; border-color:Red; " id='selectdiv'></div></td>
                                        </tr>
                                        <tr>
                                            <td></td>
                                            <td align="center"><input class='rb1-12' type="button" value='发表' onclick='save("1");checkgoto=false' />&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value='取消' /></td>
                                        </tr>
                                    </table>
                                </div>
                                <div style="border-top: #90b0de 1px solid;"></div>
                                <div id="mnglist" style="margin-top:10px;margin-bottom:10px;margin-left:10px;margin-right:10px;">
                                    
                                </div>
		                    </td>
		                </tr>
		            </table>
		        </td>
		    </tr>
		</table>
		<asp:HiddenField ID="hfid" runat="server" />
    </div>
	<div id="myhidediv" style="VISIBILITY: hidden;">
	    <asp:textbox id="txtid" runat="server" Width="2"></asp:textbox>
	</div>
    </form>

</body>
</html>
